﻿<Window x:Class="Finaltec.Hart.Analyzer.View.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:UserControls="clr-namespace:Finaltec.Hart.Analyzer.View.UserControls"
        xmlns:Converter="clr-namespace:Finaltec.Hart.Analyzer.View.Converter" xmlns:meffed="clr-namespace:MEFedMVVM.ViewModelLocator;assembly=MEFedMVVM.WPF"
        xmlns:DataTemplate="clr-namespace:Finaltec.Hart.Analyzer.ViewModel.DataTemplate;assembly=Finaltec.Hart.Analyzer.ViewModel"
        meffed:ViewModelLocator.ViewModel="MainViewModel"
        Title="Hart Analyzer" Height="350" Width="525" Style="{StaticResource WindowStyle}" MinHeight="250" MinWidth="400"
        Icon="/Hart.Analyzer;component/Images/Icon.ico" Loaded="WindowLoaded" Unloaded="WindowUnloaded" StateChanged="Window_StateChanged" 
        SizeChanged="Window_SizeChanged" LocationChanged="Window_LocationChanged">
    
    <Window.Resources>
        <Style TargetType="{x:Type UserControls:ConnectMenuItem}" x:Key="ConnectMenu">
            <Setter Property="IsConnected"  Value="{Binding IsConnected}" />
            <Setter Property="Header" Value="_Connect" />

            <Style.Triggers>
                <Trigger Property="IsConnected" Value="True">
                    <Setter Property="Header" Value="_Disconnect"></Setter>
                </Trigger>
                <Trigger Property="IsConnected" Value="False">
                    <Setter Property="Header" Value="_Connect"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        
        <Style TargetType="{x:Type TextBox}">
            <Setter Property="FontFamily" Value="Consolas" />
            <Setter Property="Background" Value="Transparent" />
            <Setter Property="Padding" Value="3,1" />
            <Setter Property="Margin" Value="1" />
            <Setter Property="IsReadOnly" Value="True" />
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="HorizontalContentAlignment" Value="Center" />
        </Style>
    </Window.Resources>

    <Grid Name="Root">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <Menu Grid.Row="0">
            <UserControls:ConnectMenuItem Style="{DynamicResource ConnectMenu}" Command="{Binding ConnectDisconnectCommand}" />
            <MenuItem Header="_Send Command" Command="{Binding SendCommand}" />
            
            <MenuItem Header="S_ettings">
                <MenuItem Header="_Connection Settings" Command="{Binding DisplayConnectionSettingsCommand}" />
                <MenuItem Header="_Swap Bytes" IsCheckable="True" IsChecked="{Binding SwapBytes}" />
            </MenuItem>
            
            <MenuItem Header="_Filter">
                <MenuItem Header="Time" Name="mnuTime" IsCheckable="True" IsChecked="{Binding Filter.DisplayTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Send or Recived" Name="mnuType" IsCheckable="True" IsChecked="{Binding Filter.DisplaySendOrRecived, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Preamble" Name="mnuPreamble" IsCheckable="True" IsChecked="{Binding Filter.DisplayPreamble, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Delimiter" Name="mnuDelimiter" IsCheckable="True" IsChecked="{Binding Filter.DisplayDelimiter, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Address" Name="mnuAddress" IsCheckable="True" IsChecked="{Binding Filter.DisplayAddress, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Command" Name="mnuCommand" IsCheckable="True" IsChecked="{Binding Filter.DisplayCommand, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Byte count" Name="mnuByteCount" IsCheckable="True" IsChecked="{Binding Filter.DisplayByteCount, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Data" Name="mnuData" IsCheckable="True" IsChecked="{Binding Filter.DisplayData, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Response" Name="mnuResponse" IsCheckable="True" IsChecked="{Binding Filter.DisplayResponse, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                <MenuItem Header="Checksum" Name="mnuChecksum" IsCheckable="True" IsChecked="{Binding Filter.DisplayChecksum, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
            </MenuItem>

            <MenuItem Header="_Info">
                <MenuItem Header="_Help" Command="{Binding HelpCommand}" />
                <MenuItem Header="_Give Feedback" Command="{Binding GiveFeedbackCommand}" />
                <MenuItem Header="_Check for Updates" Command="{Binding CheckForUpdatesCommand}" />
                <Separator />
                <MenuItem Header="_About" Command="{Binding AboutCommand}" />
            </MenuItem>
        </Menu>
        
        <ListView ItemsSource="{Binding DataTransferModel.Output}" Background="Transparent" Margin="0" VerticalContentAlignment="Top" AlternationCount="2" 
                  Name="lvOutput" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="2" ScrollViewer.CanContentScroll="False">
            <ListView.ItemTemplate>
                <DataTemplate DataType="DataTemplate:CommandData">
                    <DataTemplate.Resources>
                        <Converter:BooleanToVisibility x:Key="boolToVis" />
                    </DataTemplate.Resources>

                    <StackPanel Orientation="Horizontal" Margin="0,1">
                        <TextBox Text="{Binding Mode=OneWay, Path=DateTime, StringFormat=HH:mm:ss.fff}" VerticalAlignment="Center" Padding="0,1" ToolTip="{Binding DateTimeToolTip, Mode=OneWay}"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuTime, Converter={StaticResource boolToVis}}"/>                        
                        
                        <TextBox Text="{Binding Type, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding TypeToolTip, Mode=OneWay}" Foreground="#FF000000"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuType, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding Preamble, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding PreambleToolTip, Mode=OneWay}" Foreground="#FF1745C6"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuPreamble, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding Delimiter, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding DelimiterToolTip, Mode=OneWay}" Foreground="#FF5cc0d5"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuDelimiter, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding Address, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding AddressToolTip, Mode=OneWay}" Foreground="#FFf31c1c"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuAddress, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding Command, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding CommandToolTip, Mode=OneWay}" Foreground="#FF19b415"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuCommand, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding ByteCount, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding ByteCountToolTip, Mode=OneWay}" Foreground="#FF000000"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuByteCount, Converter={StaticResource boolToVis}}"/>

                        <UserControls:ExtendedTextBox Text="{Binding Data, Mode=OneWay}" BorderThickness="0" Background="Transparent" Padding="3,1" IsReadOnly="True" FontWeight="Normal" 
                                                    SelectedTextChanged="ExtendedTextBoxSelectedTextChanged" AutoWordSelection="True"
                                                    FontFamily="Consolas" ToolTip="{Binding DataToolTip, Mode=OneWay}" Foreground="#FFf38400" VerticalAlignment="Center"
                                                    Visibility="{Binding Path=IsChecked, ElementName=mnuData, Converter={StaticResource boolToVis}}" />

                        <TextBox Text="{Binding Response, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding ResponseToolTip, Mode=OneWay}" Foreground="#FFBE1818"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuResponse, Converter={StaticResource boolToVis}}"/>
                        
                        <TextBox Text="{Binding Checksum, Mode=OneWay}" VerticalAlignment="Center" ToolTip="{Binding ChecksumToolTip, Mode=OneWay}" Foreground="#FF24a274"
                                 Visibility="{Binding Path=IsChecked, ElementName=mnuChecksum, Converter={StaticResource boolToVis}}"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <StatusBar Grid.Row="3" Background="{StaticResource DefaultMenuBackground}">
            <TextBox Text="{Binding Value}" Margin="2,0" Padding="0" HorizontalContentAlignment="Left" TextWrapping="Wrap" MaxLines="6" />
        </StatusBar>
    </Grid>
</Window>